﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace MiniJson
{
    class Program
    {
        /// <summary>
        /// MinimalJson
        /// Take a Json string and formats so that each record is on a separate line so that can see records.
        /// Could be extended to do full JSon parse.
        /// In batch file capture the cURL output to the temp file then call this app to display the results
        /// </summary>
        /// <param name="args">The name of the temporary file that contains the JSon string</param>
        static void Main(string[] args)
        {
            // Json string to be read from temp file
            StreamReader sr = new StreamReader(args[0]);
            string jsn = sr.ReadToEnd();

            //Set of records starts with [ and ends with ]
            jsn = jsn.Replace("[", "\r\n********************* Records Begin *************************************\r\n");
            jsn = jsn.Replace("]", "\r\n********************* Records Done  *************************************\r\n");
           
            //Each record ends in } so place CR LF after so each record is on one line
            jsn = jsn.Replace("},", "}\r\n");

            //Each record begins with { so count them in the string
            int numRecords  = jsn.Split('{').Length ;
            

            //Display results
            Console.WriteLine(jsn);
            Console.WriteLine("\r\nNumber of Records= {0}\r\n", numRecords);
        }
    }
}
